/*
 * Copyright (c) 2006-2021, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2025-01-06     86157       the first version
 */

#include "set_frameInfo.h"
#include "stdio.h"
//设置发送帧的信息内容

/*
 *  #func:设置遥控命令帧信息
    #param:
        operation_instructions:操作指令
        voltage_output_range：电压输出范围选择
    #return: /
 */
ChargingControlInfo control_info;
void set_charging_param(uint8_t operation_instructions, uint8_t voltage_output_range)
{
    control_info.control_byte.reserved = 0; //预留位    
    control_info.control_byte.main_contact_status = 1; //充电回路主接触器状态(闭合)
    control_info.control_byte.power_distribution_contact_status = 1;//功率分配回路接触器状态(闭合)
    control_info.control_byte.voltage_output_range = voltage_output_range; //电压输出范围选择(高电压段)
    control_info.control_byte.operation_instructions = operation_instructions; //操作指令(快速开机)
                                                             
    control_info.group_byte.eight_group = 0; //第八组
    control_info.group_byte.seven_group = 0; //第七组
    control_info.group_byte.six_group = 0;   //第六组
    control_info.group_byte.fifty_group = 0; //第五组
    control_info.group_byte.four_group = 0;  //第四组
    control_info.group_byte.three_group = 0; //第三组
    control_info.group_byte.two_group = 0;   //第二组
    control_info.group_byte.one_group = 1;   //第一组

    control_info.group_encoding = 1;    //分组编码

    control_info.set_vdc = 0xFA0;            //给定电压 400V
    control_info.set_current = 0xBB8;        //给定电流 30A
    control_info.battery_vdc = 0xFA0;        //电池电压 400V
}


/*
 *  #func:设置定值命令帧信息
    #param:
        charg_flag:     充电接口标识
        address:        设备通信地址
        order:          定值序号
        fix_info:       定值信息
        fix_info_len:   定值信息长度
    #return: /
 */
FixedValueSet fix_val_CMD_DY;
FrameFormat format;
void SetFixVal_DYGroup(uint8_t charg_flag, uint8_t address, uint8_t order, uint8_t fix_info, uint8_t fix_info_len)
{
    fix_val_CMD_DY.charg_flag = charg_flag;         //一桩一充
    fix_val_CMD_DY.device_type = CHARGE;            //功率控制模块
    fix_val_CMD_DY.address = address;               //模块地址
    fix_val_CMD_DY.order = order;                   //定值序号
    fix_val_CMD_DY.reserved = 0x00;                 //预留信息
    fix_val_CMD_DY.fix_info = fix_info;             //动态分组模式（定值信息）
    fix_val_CMD_DY.fix_info_len = fix_info_len;     //定值信息长度

    format.frame_one = 0x01;             //第一帧
    format.frame_two = 0x02;             //第二帧
    format.frame_num = 0x02;             //共两帧
}

/*
    #func:设置分组信息
    #param:
        group_set_undo：分组设置/撤销
        addr_select：   连续/间断地址
        group_num：     组号
        addr_num：      地址数目
        addr_info：     起始地址信息
        addr_info_end： 待分配模块的终止地址
    #return: null
*/
GroupSetFrame type_group_set;
void group_set(uint8_t group_set_undo, uint8_t addr_select, uint8_t group_num, uint8_t addr_num, uint8_t addr_info, uint8_t addr_info_end)
{
    type_group_set.cmd_byte.reversed1 = 0;          //预留
    type_group_set.cmd_byte.group_set_undo = group_set_undo;  //分组设置
    type_group_set.cmd_byte.addr_select = addr_select;     //连续地址
    type_group_set.cmd_byte.reversed2 = 0;          //预留

    type_group_set.group_num = group_num;
    type_group_set.addr_num = addr_num;
    type_group_set.addr_info = addr_info;
    type_group_set.addr_info_end = addr_info_end;
}


